<?php
include '../business/model/const.php';
include '../business/model/model.php';
ini_set('display_errors',1);
if (isset($_GET['action'])) {
	switch ($_GET["action"]) {
		case ACTION_LOGIN :
			login();
			break;
		case ACTION_LOGOUT :
			logout();
			break;
		default :
			accessFail("");
	}
} else {
	accessFail("");
}

function login() {
	$userName = $_POST["username"];
	$password = $_POST["password"];
	$user = new User();
	$user->setUserName("zhaochu");
	$user->setPassword("zhaochu1680");
	if ($user->getUserName() == $userName && $user->getPassword() == $password) {
		loginSuccess($user);
	} else {
		accessFail("");
	}
}

function logout() {
	session_start();
	session_destroy();
	header("Location:a_login.php");
}

function loginSuccess($user) {
	session_start();
	$_SESSION["user"] = $user;
	header("Location:index.php");
}

function accessFail($message) {
	header("Location:a_login.php");
}
?>